#ifndef JPROCESSWATCHERPRIVATE_H
#define JPROCESSWATCHERPRIVATE_H

#include "jcprocesswatcher.h"
#include <JXQCore/JSingleton>
#include <JXQCore/JThread>
#include <JXQCore/JMutex>
#include <condition_variable>
#include <atomic>
#include <map>

namespace JXQ
{

class J_DECL_HIDDEN JListenThread : public JThread
{
	J_PERMANENT_SINGLETON(JListenThread)

public:
	void addWatcher(JProcessWatcher *q_ptr);
	void removeWatcher(JHandle pid);

public:
	void notifiy(JHandle pid, int result);

protected:
	void run() override;

private:
	std::mutex m_mutex;
	std::map<JHandle, JProcessWatcher*> m_pidMap;
};

class J_DECL_HIDDEN JProcessWatcherPrivate
{
public:
	explicit JProcessWatcherPrivate(JHandle pid);

public:
	std::atomic<JHandle> m_pid;
	std::atomic_int m_result;

	std::mutex m_mutex;
	std::condition_variable m_condition;
};

} //namespace JXQ


#endif //JPROCESSWATCHERPRIVATE_H
